const mongoose = require('mongoose');

const projectSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    trim: true
  },
  description: {
    type: String,
    trim: true
  },
  repositoryUrl: {
    type: String,
    required: true,
    trim: true
  },
  deploymentConfig: {
    branch: {
      type: String,
      default: 'master'
    },
    buildCommand: {
      type: String,
      default: 'npm run build'
    },
    outputDir: {
      type: String,
      default: 'dist'
    },
    serverConfig: {
      host: String,
      port: {
        type: Number,
        default: 22
      },
      username: String,
      path: String,
      authType: {
        type: String,
        enum: ['password', 'privateKey'],
        default: 'privateKey'
      },
      password: String,
      privateKey: String,
      passphrase: String
    }
  },
  status: {
    type: String,
    enum: ['idle', 'deploying', 'success', 'failed'],
    default: 'idle'
  },
  deployStats: {
    totalCount: {
      type: Number,
      default: 0
    },
    successCount: {
      type: Number,
      default: 0
    },
    failedCount: {
      type: Number,
      default: 0
    }
  },
  lastDeployTime: Date,
  createdAt: {
    type: Date,
    default: Date.now
  }
});

module.exports = mongoose.model('Project', projectSchema); 